local fuyao = fk.CreateSkill({
    name = "sj5__fuyao",
  })
  
  Fk:loadTranslationTable{
    ["sj5__fuyao"] = "扶摇",
    [":sj5__fuyao"] = "摸牌阶段结束时，你可以弃置至少一张牌，然后用<a href='zhongyangqu_js'>中央区</a>交换"..
    "一名其他角色的所有手牌(二者的牌数须相等)。若如此做，你执行一个额外的摸牌阶段。",
  
    ["#sj5__fuyao"] = "扶摇：你可以弃置至少一张牌",
    ["#sj5__fuyao-choose"] = "扶摇：用中央区交换一名其他角色的所有手牌，然后你执行一个额外的摸牌阶段",
  
    ["$sj5__fuyao1"] = "",
    ["$sj5__fuyao2"] = "",
  }

  fuyao:addEffect(fk.EventPhaseEnd, {
    can_trigger = function(self, event, target, player, data)
      return player:hasSkill(fuyao.name) and target == player and player.phase == Player.Draw and not player:isNude()
    end,
    on_cost = function (self, event, target, player, data)
      return #player.room:askToDiscard(player,{
        min_num = 1,
        max_num = 999,
        skill_name = fuyao.name,
        prompt = "#sj5__fuyao",
        include_equip = true,
      }) > 0
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      if #player:getTableMark("sj5__fuyao-turn") > 0 then
        local ps = table.filter(room:getOtherPlayers(player),function (p)
          return p:getHandcardNum() == #player:getTableMark("sj5__fuyao-turn")
        end)
        if #ps > 0 then
          local p = room:askToChoosePlayers(player,{
            targets = ps,
            min_num = 1,
            max_num = 1,
            skill_name = fuyao.name,
            prompt = "#sj5__fuyao-choose",
            cancelable = false,
          })[1]
          room:swapCardsWithPile(p,p:getCardIds("h"),player:getTableMark("sj5__fuyao-turn"),fuyao.name,"discardPile",true,player)
          player:gainAnExtraPhase(Player.Draw,fuyao.name,false)
        end
      end
    end,
  })

  fuyao:addEffect(fk.AfterCardsMove, {
  can_refresh = function(self, event, target, player, data)
    if player:hasSkill(fuyao.name, true) then
      for _, move in ipairs(data) do
        if move.toArea == Card.DiscardPile then
          for _, info in ipairs(move.moveInfo) do
            if table.contains(player.room.discard_pile, info.cardId) then
              return true
            end
          end
        end
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.DiscardPile and not table.contains(player.room.discard_pile, info.cardId) then
            return true
          end
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local ids = player:getTableMark("sj5__fuyao-turn")
    for _, move in ipairs(data) do
      if move.toArea == Card.DiscardPile then
        for _, info in ipairs(move.moveInfo) do
          if table.contains(room.discard_pile, info.cardId) then
            table.insertIfNeed(ids, info.cardId)
          end
        end
      end
      for _, info in ipairs(move.moveInfo) do
        if info.fromArea == Card.DiscardPile and not table.contains(room.discard_pile, info.cardId) then
          table.removeOne(ids, info.cardId)
        end
      end
    end
    room:setPlayerMark(player, "sj5__fuyao-turn", ids)
  end,
  })

  return fuyao